<?php 
require_once '../model/moduleuser.php';
require_once '../model/background_images.php';

$moduleObj = new Model_ModuleUser();
$imageObj  = new Model_Background_Images();


if(!empty($_FILES)) {
	
	if($_FILES['back_image']['name']!='') {
		$size =	getimagesize($_FILES['back_image']['tmp_name']);
		$imageWidth  = '280';
		$imageHeight = '42';
		if($_FILES['back_image']['name']!= '' && ($size[0] == $imageWidth && $size[1] == $imageHeight) ) {
			$path = '../uploads/logo/';
			$imageName    = $_FILES['back_image']['name'];
			$arrImageName = explode(".",$imageName);
			$position     = count($arrImageName);
			$fileName     = date('Ymdhis').".".$arrImageName[$position-1];
			copy($_FILES["back_image"]["tmp_name"],$path.$fileName);
			$imageArray = array();
			$imageArray['image_name'] = $_FILES['back_image']['name'];
			$imageArray['image_path'] = $fileName;
			$imageObj->addBackgroundImage($imageArray);
			$_SESSION['msg'] = "<div class='success_msg'><span>Image added successfully !</span></div>";
			header('location:'.SITE_URL.'/admin/home.php?q=manageimages');
			exit;
		}
		else {
			$_SESSION['msg'] = "<div class='error_msg'><span>Please select image with dimensions 280X42</span></div>";
			header('location:'.SITE_URL.'/admin/home.php?q=addImage');
			exit;
		}
		
	}
}

## Assign success or error msg to smarty variable and unset session variable
if(isset($_SESSION['msg']) && $_SESSION['msg']!= '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}
$smarty->assign('activeclass', 'manageimages');
$smarty->assign('mainmenu', '5');

$smarty->display(TEMPLATEDIR_ADMIN. 'settings/add_image.tpl');
unset($smarty);
?>